package com.ruoyi.system.service.msg.enricher;

import com.ruoyi.system.domain.PmMaterialItem;
import com.ruoyi.system.domain.PmMaterialList;
import com.ruoyi.system.entity.MsgPushTaskDO;
import com.ruoyi.system.enums.MsgTypeEnum;
import com.ruoyi.system.mapper.PmMaterialItemMapper;
import com.ruoyi.system.mapper.PmMaterialListMapper;
import com.ruoyi.system.service.IPmMaterialItemService;
import com.ruoyi.system.service.IPmMaterialListService;
import com.ruoyi.system.service.msg.MsgDetailEnricher;
import com.ruoyi.system.vo.H5MsgDetailVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 主材清单消息详情丰富器
 * 用于丰富主材清单类型消息的详情信息，包括清单详情和清单明细
 *
 * @author ruoyi
 * @since 2024-01-01
 */
@Component
public class MaterialListMsgEnricher implements MsgDetailEnricher {

    @Resource
    private IPmMaterialListService pmMaterialListService;

    @Resource
    private IPmMaterialItemService pmMaterialItemService;

    @Override
    public boolean supports(Integer msgType) {
        return Objects.equals(msgType, MsgTypeEnum.MATERIAL_LIST.getCode());
    }

    @Override
    public void enrich(H5MsgDetailVO vo, MsgPushTaskDO task) {
        if (task.getBusinessId() == null || task.getBusinessId().trim().isEmpty()) {
            return;
        }
        vo.setMaterialItems(pmMaterialItemService
                .getBudgetGroupListByListIdWithCategorySplit(Long.valueOf(task.getBusinessId())));
    }
}


